<template>
  <div class="echarts-outer-wrapper width-410">
    <div @click="ItemLeftMiddleBtn()" style="cursor: pointer">
      <Title title="纳税申报" time="1"></Title>
    </div>
    <div class="content-wrapper">
      <div class="top-wrapper">
        <div>
          <div class="item-wrapper">
            <img src="~@/assets/images/icon-day.png" class="icon-wrapper" />
            <div class="title">本日</div>
            <div class="num-list">
              <div
                class="num-item blue"
                v-for="(item, index) in todayData.brsbhs"
                :key="index"
              >
                {{ item }}
              </div>
            </div>
            <div class="dw blue">户</div>
          </div>
          <div class="item-wrapper">
            <img src="~@/assets/images/icon-month.png" class="icon-wrapper" />
            <div class="title">本日</div>
            <div class="num-list">
              <div
                class="num-item yellow"
                v-for="(item, index) in todayData.brsbje"
                :key="index"
              >
                {{ item }}
              </div>
            </div>
            <div class="dw yellow">万元</div>
          </div>
        </div>
      </div>
      <div class="bottom-wrapper">
        <div class="left">
          <div class="title">本月已/应申报</div>
          <div class="num-dw blue">
            <div class="num">{{ EchartData.yjsb }}/{{ EchartData.ygsb }}</div>
            <div class="dw">万户次</div>
          </div>
        </div>
        <div class="center" v-if="EchartData">
          <div class="num-dw">
            <div class="num">{{ EchartData.sbl }}</div>
            <div class="dw"></div>
          </div>
          <div class="name">申报率</div>
        </div>
        <div class="right">
          <div class="title">本月申报金额</div>
          <div class="num-dw yellow">
            <div class="num">{{ EchartData.sbje }}</div>
            <div class="dw">万元</div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import Title from "@/components/title";
import { FormateDate } from "@/utils/util.js";

export default {
  inject: ["reload"],
  components: { Title },
  name: "sstjzz",
  data() {
    return {
      prevDate: "",
      specificDate: "",
      todayData: {},
      EchartData: [],
      timer: null,
      nextUpdateTime: null,
    };
  },
  created() {
    let date = "";
    let specificDate = "";
    let month = new Date().getMonth() + 1;
    let year = new Date().getFullYear();
    let day = new Date().getDate();
    date = year + "-" + month;
    specificDate = year + "-" + month + "-" + day;
    this.prevDate = date;
    this.specificDate = specificDate;
  },
  mounted() {
    this.ajax({
      url: "/dpzsSycxService/sstjzzQuery",
      method: "post",
      data: {
        param: {
          tjny: this.prevDate,
        },
      },
    }).then((res) => {
      res = res.data;
      if (res.rtnCode !== "200") {
        this.$message.error(res.rtnMsg);
        return;
      }
      this.EchartData = res.data;
    });
    //本日数据
    this.getTodayData();
    this.timer = setInterval(() => {
      if (this.nextUpdateTime && this.nextUpdateTime == FormateDate()) {
        this.getTodayData();
      }
    }, 1000);
  },
  beforeDestroy() {
    clearInterval(this.timer);
    this.timer = null;
  },
  methods: {
    ItemLeftMiddleBtn() {
      this.$router.push("/shenbao");
    },
    getTodayData() {
      this.ajax({
        url: "/dpzsSycxService/sstjzzbrsbhsjeQuery",
        method: "post",
        data: {
          param: {
            tjrq: this.specificDate,
          },
        },
      }).then((res) => {
        res = res.data;
        if (res.rtnCode !== "200") {
          this.$message.error(res.rtnMsg);
          return;
        }
        this.todayData = res.data;
        this.nextUpdateTime = res.data.xcsxsj;
        this.reload();
      });
    },
  },
};
</script>

<style scoped lang="scss">
.echarts-outer-wrapper {
  width: 458px;
  height: 314px;
}
.content-wrapper {
  height: 256px;
  .top-wrapper {
    margin: 10px 0;
    display: flex;
    justify-content: center;
    .item-wrapper {
      margin: 10px 0;
      display: flex;
      justify-content: flex-start;
      align-items: center;
      .icon-wrapper {
        width: 42px;
        height: 42px;
      }
      .title {
        margin: 6px;
        font-size: 16px;
        margin-right: 6px;
        color: #ffffff;
      }
      .num-list {
        margin: 0 2px 0 6px;
        display: flex;
        .num-item {
          margin: 0 1px;
          width: 24px;
          height: 32px;
          line-height: 28px;
          border-radius: 6px;
          font-size: 24px;
          box-sizing: border-box;
          text-align: center;
          color: #ffffff;
        }
        .blue {
          border: 2px solid rgba(118, 189, 255, 1);
          background-color: rgba(118, 189, 255, 0.3);
        }
        .yellow {
          border: 2px solid rgba(251, 230, 113, 1);
          background-color: rgba(251, 230, 113, 0.3);
        }
      }
      .dw {
        margin-left: 6px;
        margin-top: 12px;
        font-size: 14px;
        &.blue {
          color: rgba(159, 229, 255, 1);
        }
        &.yellow {
          color: rgba(251, 230, 113, 1);
        }
      }
    }
  }
  .bottom-wrapper {
    margin-top: 16px;
    display: flex;
    justify-content: center;
    align-items: center;
    .left {
      flex: 1;
    }
    .center {
      flex: 0 0 80px;
      width: 80px;
      height: 80px;
      background-image: url(~@/assets/images/bg-echart-1.png);
      background-size: 100% 100%;
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
      color: #ffffff;
      .num-dw {
        display: flex;
        align-items: center;
        .num {
          font-size: 24px;
          font-weight: 700;
          white-space: nowrap;
        }
        .dw {
          margin-top: 6px;
          font-size: 14px;
          white-space: nowrap;
        }
      }
    }
    .right {
      flex: 1;
    }
    .left,
    .right {
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
    }
    .title {
      margin-bottom: 6px;
      font-size: 18px;
      color: #eff0f1;
      padding: 0 12px;
      background-image: url(~@/assets/images/bg-sub-title.png);
      background-size: 120px 12px;
      background-position: left bottom;
      background-repeat: no-repeat;
      white-space: nowrap;
    }
    .num-dw {
      display: flex;
      align-items: center;
      &.blue {
        color: rgba(159, 229, 255, 1);
      }
      &.yellow {
        color: #fbe671;
      }
      .num {
        font-size: 24px;
        font-weight: 700;
        white-space: nowrap;
      }
      .dw {
        margin-top: 6px;
        font-size: 14px;
        white-space: nowrap;
      }
    }
  }
}
</style>
